import 'package:flutter/material.dart';
import './model/post.dart';
class SliverDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            title: Text('导航'),
            backgroundColor: Colors.yellow,
//            pinned: true,  //是否 固定 导航不随着 滚动
            floating: false,
            expandedHeight: 150.0,  //伸展 高度
            flexibleSpace: FlexibleSpaceBar(
              title: Text(
                '王松锋'.toUpperCase(),
                style: TextStyle(
                  fontSize: 15.0,
                  letterSpacing: 3.0,
                  fontWeight: FontWeight.w400,
                ),
              ),
              background: Image.network(
                  'https://img04.sogoucdn.com/app/a/100520021/ee1704a14f4dcd03702c01e02746449b',
                fit: BoxFit.cover,
              ),
            ),
            
          ),
          SliverSafeArea(
            sliver: SliverPadding(
              padding: EdgeInsets.all(8.0),
              sliver: SliverListDemo(),
            ),
          )
        ],
      ),
    );
  }
}


class SliverGridDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SliverGrid(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        crossAxisSpacing: 8.0,
        mainAxisSpacing: 8.0,
      ),
      delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index){
            return Container(
              child: Image.network(
                posts[index].imageUrl,
                fit: BoxFit.cover,
              ),
            );
          },
          childCount: posts.length
      ),
    );
  }
}

class SliverListDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SliverList(
        delegate: SliverChildBuilderDelegate(
           (BuildContext context, int index) {
              return Padding(
                padding: EdgeInsets.only(bottom: 32.0),
                child: Material(
                  borderRadius: BorderRadius.circular(2.0),
                  elevation: 14.0,
                  shadowColor: Colors.grey.withOpacity(0.5),
                  child: Stack(
                    children: <Widget>[
                      AspectRatio(
                        aspectRatio: 1.0,
                        child: Image.network(
                          posts[index].imageUrl,
                          fit: BoxFit.cover,
                        ),
                      ),

                      Positioned(
                        top: 32.0,
                        left: 32.0,
                        child: Column(
                          children: <Widget>[
                            Text(
                              posts[index].title,
                              style: TextStyle(
                                fontSize: 20.0,
                                color: Colors.white,

                              ),
                            ),
                            Text(
                              posts[index].author,
                              style: TextStyle(
                                fontSize: 13.0,
                                color: Colors.white,

                              ),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              );
            },
          childCount: posts.length
        ),
    );
  }
}

